/*
 * 
 * Libman
 * 
 * Daniel Kaufmann, Martin Lang, Simon Moosbrugger,
 * Stefan Mayer, Stephan Halbeisen
 * 
 */
package model.dao;

import java.util.ArrayList;
import java.util.List;

import model.Keyword;
import model.Medium;

/**
 * A DAO implementation for Medium objects.
 */

public class MediumDAO extends GenericHibernateDAO<Medium, Long> {
	// implementation in parent class
	/**
	 * Search medium.
	 * 
	 * @param words
	 *            the words
	 * @param maxResults
	 *            the max results
	 * @return the list
	 */
	public List<Medium> searchMedium(String[] words, int maxResults) {
		List<Keyword> keywords = DAOFactory.getInstance().getKeywordDAO()
				.getKeywords(words);

		List<Medium> mediums = new ArrayList<Medium>();
		for (Keyword keyword : keywords) {
			for (Medium medium : keyword.getMediums()) {
				if (!mediums.contains(medium)) {
					mediums.add(medium);
				}
			}
		}

		return mediums;
	}
}
